package org.academic.texteditor.gui.feature;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

public abstract class Feature extends JPanel {

	private static final long serialVersionUID = -3469934103235188980L;

	private final List<Feature> children;

	private Feature parentFeature;

	public Feature() {
		this.children = new ArrayList<Feature>();
	}

	public Feature getParentFeature() {
		return parentFeature;
	}

	public void setParentFeature(Feature parent) {
		this.parentFeature = parent;
	}

	@Override
	public Component add(Component component) {
		registerFeature(component);
		return super.add(component);
	}

	@Override
	public Component add(Component component, int index) {
		registerFeature(component);
		return super.add(component, index);
	}
	
	@Override
	public void add(Component component, Object constraints) {
		registerFeature(component);
		super.add(component, constraints);
	}

	public List<Feature> getChildren() {
		return children;
	}

	private void registerFeature(Component component) {
		if (component instanceof Feature) {
			children.add((Feature) component);
		}
	}
	
}
